# @Time : 2024-11-01 14:25
# @Author : Fioman 
# @Phone : 13149920693
"""
生成器表达式: (expression for element in iterable if expression)
生成器表达式的结果是一个生成器对象,可以迭代和使用next()进行访问
"""
from collections.abc import Iterator

genExp = (abs(x) for x in range(-3, 3))
print(genExp, type(genExp), isinstance(genExp, Iterator))  # True,是迭代器
print(next(genExp))
print(next(genExp))

for i in genExp:
    print(i, end=" ")

genExp.send(None)  # 再去访问的时候就会报StopIteration异常了
